package cn.lijigou.shopping;

import java.io.Serializable;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;

import cn.lijigou.shopping.domain.Image;
import cn.lijigou.shopping.domain.MResult;
import cn.lijigou.shopping.domain.Shop;
import cn.lijigou.shopping.service.MSystem;
import cn.lijigou.shopping.service.ServerService;
import cn.lijigou.shopping.util.GetSingleThreadPool;
import cn.lijigou.shopping.util.LoadImageAysnc;
import cn.lijigou.shopping.util.LoadImageAysnc.ImageCallBack;
import android.R.color;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextPaint;
import android.util.Log;
import android.view.ContextThemeWrapper;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.view.animation.AnimationSet;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView.OnItemClickListener;


public class ShoppingsActivity extends MActivity implements OnClickListener, Serializable,OnTouchListener{
	public static final int NOT_HAVE_SHOP_DATE = 0;
	public static final int NOTIFY_DATA_SET_CHANGED = 1;
	public static final int SET_SHOPPINGS = 2;
	static String aread = "";//商圈
	static String keyword = "";//关键字
	private TextView back= null;
 
	private TextView title_center= null;
	private MainTabActivity parentTab ;
	private ListView lv_shop = null;
	private MadapterShop adapterShop = null;
	static LoadImageAysnc loadImageAysnc;
	private View footerView;
	
	private View load_one;
	private View load_two;
	private TextView home_btn3;
	private TextView home_btn1;
	private TextView home_btn2;
	public static  String distance = "300000000";
	private List<Shop> temp_shops=null; 
	private Spinner spinner;
	public int action = 1;
	public static int sort = 0;
	public static int order = 2;
	Map<Integer,ImageView> iconMap;
	Map<Integer,TextView> textMap;
	private ImageView  home_icon1 ;
	private ImageView  home_icon2 ;
	private ImageView  home_icon3;
	public String all_flower_data = "";
	private ExecutorService executorService = GetSingleThreadPool.getInstance();
	
	public Handler waitHander = new Handler(){
		
		public void handleMessage(Message msg) {
			super.handleMessage(msg);
			if(msg.what==NOTIFY_DATA_SET_CHANGED){
				List<Shop> temp_shops = new ArrayList<Shop>();
				adapterShop.setDate(new ArrayList<Shop>(HomeActivity.dataSource.get(HomeActivity.dataType)));
				adapterShop.notifyDataSetChanged();
				if(HomeActivity.dataType==11){
					if(HomeActivity.dataSource.get(HomeActivity.dataType).size()==0){
						waitHander.sendEmptyMessage(NOT_HAVE_SHOP_DATE);
						waitHander.sendEmptyMessage(102);
					}
				}
//					bottom_linear.setVisibility(View.GONE);
			}else if(msg.what==NOT_HAVE_SHOP_DATE){
				TextView tv = (TextView)ShoppingsActivity.this.findViewById(R.id.shopping_empty);
				if("".equals(keyword)){
					tv.setTextColor(Color.BLACK);
					tv.setText(R.string.see_other_categories);  
				}else{
					tv.setTextColor(Color.BLACK);
					tv.setText(R.string.did_not_buy_the_search);   
				}
				lv_shop.setEmptyView(tv);
			}else if(msg.what==ShoppingsActivity.SET_SHOPPINGS){
				getShops();
			}else if(msg.what==3){
				adapterShop.notifyDataSetChanged();
			}else if(msg.what==101){
				load_one.setVisibility(View.VISIBLE);
				load_two.setVisibility(View.GONE);
			}else if(msg.what==102){
				load_one.setVisibility(View.GONE);
				load_two.setVisibility(View.GONE);
			}else if(msg.what==103){
				load_one.setVisibility(View.GONE);
				load_two.setVisibility(View.VISIBLE);
			}else if(msg.what==104){
				if(HomeActivity.dataSource.get(HomeActivity.dataType).size()==0){
					 Toast.makeText(ShoppingsActivity.this,"亲,没有分类数据哦,请查看别的分类", 1).show(); 
				}else{
					 Toast.makeText(ShoppingsActivity.this,"亲,已经是最后一条了哦", 1).show(); 
				}
				load_one.setVisibility(View.GONE);
				load_two.setVisibility(View.GONE);
			}
		}
	};
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		keyword = "";
		requestWindowFeature(Window.FEATURE_NO_TITLE); 
		setContentView(R.layout.shoppings);
		overridePendingTransition(R.anim.push_in,R.anim.push_out);
		parentTab=(MainTabActivity)ShoppingsActivity.this.getParent();
		initView();
		initData();
		

	}
	private void initData() {
		// TODO Auto-generated method stub
		Intent intent = this.getIntent();
		if(intent.hasExtra("keyword")){
			keyword = intent.getStringExtra("keyword");//关键字
			
		}else {
			keyword="";
		}
		 
		if("".equals(keyword)){
			if(HomeActivity.dataSource.get(HomeActivity.dataType).size()==0){
				HomeActivity.isload[HomeActivity.dataType]=true;
				new MSystem(this).timer_location_shoppings(this);
				
			}else{
				adapterShop.setDate(HomeActivity.dataSource.get(HomeActivity.dataType));
				adapterShop.notifyDataSetChanged();
			}
			
		}else{
			//搜索
			this.findViewById(R.id.shopping_top).setVisibility(View.GONE);
			HomeActivity.dataSource.get(HomeActivity.dataType).clear();
			HomeActivity.dataPage[HomeActivity.dataType]=1;
			HomeActivity.isload[HomeActivity.dataType]=true;
			searchShops();
			ShopDetailActivity.mList.add(this);
		}
	}



	private void initView() {
		sort = 0;
		order = 2;
		distance = "300000000";
		iconMap=new HashMap<Integer, ImageView>();
		textMap=new HashMap<Integer, TextView>();
		home_btn1 = (TextView)findViewById(R.id.Home_btn1);
		home_btn2 = (TextView)findViewById(R.id.Home_btn2);
		home_btn3 = (TextView)findViewById(R.id.Home_btn3);
		
		if(MSystem.areaName.equals("")){
			home_btn1.setText("商圈");
		}else{
			home_btn1.setText((MSystem.areaName.split("/")[0]));
		}
		textMap.put(R.id.home_left, home_btn1);
		textMap.put(R.id.home_center, home_btn2);
		textMap.put(R.id.home_right, home_btn3);
		
		RelativeLayout home_left = ((RelativeLayout)findViewById(R.id.home_left));
		RelativeLayout home_center = ((RelativeLayout)findViewById(R.id.home_center));
		RelativeLayout home_right = ((RelativeLayout)findViewById(R.id.home_right));
		
		home_left.setOnClickListener(this);
		home_center.setOnClickListener(this);
		home_right.setOnClickListener(this);
		
	    home_icon1 = (ImageView)findViewById(R.id.home_icon1);
	    home_icon2 = (ImageView)findViewById(R.id.home_icon2);
	    home_icon3 = (ImageView)findViewById(R.id.home_icon3);
	    iconMap.put(R.id.home_left, home_icon1);
	    iconMap.put(R.id.home_center, home_icon2);
	    iconMap.put(R.id.home_right, home_icon3);
	    
	    
	    home_left.setOnTouchListener(this);
	    home_center.setOnTouchListener(this);
	    home_right.setOnTouchListener(this);
//		home_btn1.setOnClickListener(this);
//		home_btn2.setOnClickListener(this);
//		home_btn3.setOnClickListener(this);
		
		back = (TextView) this.findViewById(R.id.title_btn_left);
		back.setBackgroundResource(R.drawable.title_back_normal);
//		back.setBackgroundResource(R.drawable.title_btn);c
		this.findViewById(R.id.titleRightView).setVisibility(View.GONE);
 
		this.findViewById(R.id.titleLeftView).setOnClickListener(this);
		
		
		title_center = (TextView) this.findViewById(R.id.text_center);
		updateTitle(HomeActivity.dataType+"");
		lv_shop = (ListView) this.findViewById(R.id.lv_shops);
		adapterShop = new MadapterShop(this,HomeActivity.dataSource.get(HomeActivity.dataType),lv_shop);
		footerView= LayoutInflater.from(this).inflate(R.layout.list_bottom_line, null);
		load_one=footerView.findViewById(R.id.load_one);
		load_two=footerView.findViewById(R.id.load_two);
		
		if(!HomeActivity.isload[HomeActivity.dataType]){
			load_one.setVisibility(View.GONE);
		}else{
			load_one.setVisibility(View.VISIBLE);
		}
		load_two.setVisibility(View.GONE);
		load_two.setOnClickListener(this);
		lv_shop.addFooterView(footerView);
		lv_shop.setAdapter(adapterShop);
		lv_shop.setOnScrollListener(listScrollListenerShop);
		lv_shop.setOnItemClickListener(clickListenerShop);
	}
	
	
 
	
	public void onClick(View v) {
		MSystem.pv+=1;
		switch (v.getId()) {
			case R.id.titleLeftView:
				if(ShopDetailActivity.mList.contains(this)){
	    			ShopDetailActivity.mList.remove(this);
				}
	    		if(parentTab!=null){
		    		 parentTab.mHost.setCurrentTabByTag("home_tab");
		    		 parentTab.main_tab_home.setChecked(true);
	    		}else{
	    			this.finish();
	    		}
				break;
			case R.id.load_two:
			       getShops();
				break;
			case R.id.home_left:
				ShoppingsActivity.this.startActivityForResult(new Intent(ShoppingsActivity.this, DialogWidgetActivity.class),1);
				
				
//				if(!MSystem.area.trim().equals("")){
//					MSystem.area="";
//					MSystem.areaName="";
//					initDataSource();
//					adapterShop.setDate(new ArrayList<Shop>());
//					adapterShop.notifyDataSetChanged();
//					getShops();
//					
//				}
				break;
			case R.id.home_center:
				select_distance();
				break;
			case R.id.home_right:
				sort=1;
				if(order==2){
					home_btn3.setText("由低到高");
					order=1;
				}else{
					order=2;
					home_btn3.setText("由高到低");
				}
				initDataSource();
				adapterShop.setDate(new ArrayList<Shop>());
				adapterShop.notifyDataSetChanged();
				getShops();
				break;
		}
	}
	
	
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		if(!HomeActivity.isload[HomeActivity.dataType]){
			load_one.setVisibility(View.GONE);
		}else{
			load_one.setVisibility(View.VISIBLE);
		}
		
	}



	
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		if(resultCode==1){
			initDataSource();
			adapterShop.setDate(new ArrayList<Shop>());
			adapterShop.notifyDataSetChanged();
			getShops();
			if(MSystem.areaName.equals("")){
				home_btn1.setText("商圈");
			}else{
				home_btn1.setText((MSystem.areaName.split("/")[0]));
			}
		}
	}
	private void initDataSource() {
 
		if(HomeActivity.dataType==12){
			sort = 0;
			order = 2;
			distance = "300000000";
		}
		// TODO Auto-generated method stub
		for(int i=0;i<HomeActivity.dataSource.size();i++){
			HomeActivity.dataPage[i] = 1;
			HomeActivity.dataSource.get(i).clear();
			HomeActivity.isload[i]=true;
		}
	}

	private void getShops(){
		if(HomeActivity.recordError.contains(HomeActivity.dataType+"")){
			HomeActivity.recordError.remove(HomeActivity.dataType+"");
			HomeActivity.isload[HomeActivity.dataType]=true;
		} 
		if(HomeActivity.isload[HomeActivity.dataType]){
    		HomeActivity.isload[HomeActivity.dataType] = false;
    		//显示加载中
    		waitHander.sendEmptyMessage(101);
			if(getNetConnectState(ShoppingsActivity.this)){
				
				if(MSystem.mLocation!=null){
					executorService.execute(new Thread() {
						public void run() {
							Log.d("threadpool", "getShops----run---" + Thread.currentThread().getName());
							Boolean temp = false;
							MResult mResult;

							if (HomeActivity.dataSource.get(HomeActivity.dataType).size() == 0) {
								HomeActivity.dataPage[HomeActivity.dataType] = 1;
							} else {
								HomeActivity.dataPage[HomeActivity.dataType] = HomeActivity.dataPage[HomeActivity.dataType] + 1;
							}

							if (HomeActivity.dataType == 11) {
								mResult = MSystem.searchShops(HomeActivity.dataSource.get(HomeActivity.dataType),
										HomeActivity.dataPage[HomeActivity.dataType], keyword);
							} else if (HomeActivity.dataType == 12) {
								mResult = MSystem.getShopsFromAround(HomeActivity.dataSource.get(HomeActivity.dataType),
										HomeActivity.dataPage[HomeActivity.dataType], HomeActivity.tempdataType + "", MSystem.area,
										distance + "", sort, order);
							} else {
								mResult = MSystem.getShopsFromAround(HomeActivity.dataSource.get(HomeActivity.dataType),
										HomeActivity.dataPage[HomeActivity.dataType], HomeActivity.dataType + "", MSystem.area, distance
												+ "", sort, order);
							}

							if (mResult != null) {
								if (mResult.isSuccess()) {
									waitHander.sendEmptyMessage(NOTIFY_DATA_SET_CHANGED);
									temp = mResult.isPage();
									if (!mResult.isPage()) {
										// if(HomeActivity.dataPage[HomeActivity.dataType]==1){
										// temp=true;
										// }else{
										waitHander.sendEmptyMessage(102);
										if (HomeActivity.dataSource.get(HomeActivity.dataType).size() > 8) {
											MainTabActivity.showHander.sendEmptyMessage(102);
										}
										// }
									}
								} else {
									waitHander.sendEmptyMessage(104);
								}
							} else {
								HomeActivity.dataPage[HomeActivity.dataType] = HomeActivity.dataPage[HomeActivity.dataType] - 1;
								HomeActivity.recordError.add(HomeActivity.dataType + "");
								waitHander.sendEmptyMessage(103);
							}
							HomeActivity.isload[HomeActivity.dataType] = temp;
						}
					});
				}else{
					HomeActivity.recordError.add(HomeActivity.dataType+"");
					waitHander.sendEmptyMessage(103);
				}
			}else{
					HomeActivity.recordError.add(HomeActivity.dataType+"");
					waitHander.sendEmptyMessage(103);
			}	
    	} 
	}

	public void updateTitle(final String type) {
		int temp_type=0;
		try {
			temp_type =Integer.parseInt(type);
		} catch (Exception e) {
			// TODO: handle exception
			temp_type=0;
			e.printStackTrace();
			
		}
		switch (temp_type) {
		case 1:
			title_center.setText(R.string.food);
			break;
		case 2:
			title_center.setText(R.string.movie_ticket);
			break;
		case 3:
			title_center.setText(R.string.ktv);
			break;
		case 4:
			title_center.setText("酒店");
			break;
		case 5:
			title_center.setText("健身");
			break;
		case 6:
			title_center.setText("汽车服务");
			break;
		case 7:
			title_center.setText("美容");
			break;
		case 8:
			title_center.setText("景点门票");
			break;
		case 9:
			title_center.setText("养生按摩");
			break;
		case 10:
			title_center.setText("鲜花");
			break;
	 
		case 11:
			title_center.setText("搜索结果");
			break;
		default:
			break;
		}
	}
	private void searchShops(){
		executorService.execute(new Thread() {
			public void run() {
				Log.d("threadpool","searchShops----run---"+Thread.currentThread().getName());
				MResult mResult = null;
				if (MSystem.mLocation != null) {
					mResult = MSystem.searchShops(HomeActivity.dataSource.get(HomeActivity.dataType),
							HomeActivity.dataPage[HomeActivity.dataType], keyword);
				}
				if (mResult != null) {
					waitHander.sendEmptyMessage(ShoppingsActivity.NOTIFY_DATA_SET_CHANGED);
				} else {
					if (HomeActivity.dataPage[HomeActivity.dataType] == 1) {
						waitHander.sendEmptyMessage(ShoppingsActivity.NOT_HAVE_SHOP_DATE);
					}
				}
			}
		});
	}
	public class MadapterShop extends BaseAdapter {
		private LayoutInflater mInflater;
		private List<Shop> shopList;
		private ListView listView;
		public  class ViewHolderShop {
			public ImageView shop_image;
			private TextView info;
			private TextView current_price;
			private TextView distance;
			private TextView saved_price;
			private TextView source;
			private TextView address;
			public Integer shopid;
			private String imageUrl;
			private Drawable shop_drawable;
		}
		public MadapterShop(Activity a,List<Shop> shopList,ListView listview) {
			this.mInflater = LayoutInflater.from(a);
			this.shopList=shopList;
			this.listView = listview;
			loadImageAysnc = new LoadImageAysnc(a);
		}

		public int getCount() {
			return shopList.size();
		}

		public void setDate(List<Shop> shopList) {
			
			this.shopList=shopList;
		}
		
		public Object getItem(int arg0) {
			return null;
		}

		public long getItemId(int arg0) {
			return 0;
		}
		ViewHolderShop holder = null;
		public View getView(int position, View convertView, ViewGroup parent) {
			if (convertView == null) {
				holder = new ViewHolderShop();
				convertView = mInflater.inflate(R.layout.list_item_shop, null);
				holder.shop_image = (ImageView) convertView.findViewById(R.id.shop_image);
				holder.info = (TextView) convertView.findViewById(R.id.info);
				holder.current_price = (TextView) convertView.findViewById(R.id.current_price);
				holder.distance = (TextView) convertView.findViewById(R.id.distance);
				holder.saved_price = (TextView) convertView.findViewById(R.id.saved_price);
				holder.source = (TextView) convertView.findViewById(R.id.source);
				holder.address = (TextView) convertView.findViewById(R.id.address);
				
				convertView.setTag(holder);
			} else {
				holder = (ViewHolderShop) convertView.getTag();
			}
			TextPaint tp = holder.saved_price.getPaint();
            tp.setFakeBoldText(true); 

			Shop shop = shopList.get(position);
			String  current_price = shop.getPrice();
			String  source = shop.getSource();   
			String  info = shop.getTitle();
			String  distance = shop.getDistance();
			String 	old_price = shop.getValue();
			String  flower_title = shop.getTitle();
			
			if(HomeActivity.dataType==10){
				holder.address.setText("全国百余省市自治区均可送达");
			}else{
				holder.address.setText(shop.getShop_address());
			}
			
			
			
			
			holder.source.setText(shop.getSource());
			
			final String imageUrl = shop.getPhoto_small();
    		final String id = shop.getId();
    		int shopid=0;
    		try{
    			 shopid=Integer.parseInt(id);
    		}catch (Exception e) {
				// TODO: handle exception
    			shopid=0;
    			e.printStackTrace();
			}
//    		holder.progressBar.setTag(imageUrl);
			holder.shop_image.setTag(id);
			
			
			
			
			//开始异步加载数据
			Drawable drawable = loadImageAysnc.loadImage(position,shopList.get(position).getId(), shopList.get(position).getPhoto_small(), "small.jpg",new ImageCallBack() {
				
				
				public void imageLoaded(Drawable drawable, int iconSrc) {
					// TODO Auto-generated method stub
					ImageView imageViewTag = (ImageView) listView.findViewWithTag(id);
					if(imageViewTag != null) {
						imageViewTag.setBackgroundDrawable(drawable);
					}
					ProgressBar progressBar = (ProgressBar) listView.findViewWithTag(imageUrl);
					if(progressBar != null) {
						progressBar.setVisibility(View.GONE);
					}
					
				}
			} );
				
			
			if(drawable == null) {
				 holder.shop_image.setBackgroundResource(R.drawable.load_small);
			} else {
				 holder.shop_image.setBackgroundDrawable(drawable);
			}
			
			source = source.replaceAll(" ", "");
			holder.info.setText(info);
			holder.distance.setVisibility(View.VISIBLE);
			try{  
				if(isNull(distance)){
					Double mDistance = Double.parseDouble(distance);
					if(mDistance == 0.0){
						holder.distance.setVisibility(View.GONE);
					}else if( mDistance >0 & mDistance <1000 ){
						holder.distance.setText(mDistance+"m");
						
					}else if(mDistance>1000){
						mDistance = mDistance/1000;
						BigDecimal b = new BigDecimal(mDistance);  
						double f1 = b.setScale(1,BigDecimal.ROUND_HALF_UP).doubleValue();  
						holder.distance.setText(f1+"km");
					}
				}
				
			}catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
			}
			if(isNull(current_price)&&!current_price.equals(getIdToString(R.string.No_).trim())){
					holder.current_price.setText(getIdToString(R.string.current_price_symbol)+current_price);
				}else{
					holder.current_price.setText(getIdToString(R.string.price_No));
				}
			if(isNull(old_price)&&!old_price.equals(getIdToString(R.string.No_).trim())){
				Double mSavePrice = Double.parseDouble(old_price)-Double.parseDouble(current_price);
				BigDecimal b = new BigDecimal(mSavePrice);  
				double f1 = b.setScale(1,BigDecimal.ROUND_HALF_UP).doubleValue(); 
				
				if((HomeActivity.dataType+"").equals("76") | (HomeActivity.dataType+"").equals("77") | (HomeActivity.dataType+"").equals("78")){
					holder.saved_price.setTextColor(Color.RED);
					holder.saved_price.setTextSize(14);
					holder.saved_price.setText(getIdToString(R.string.current_price_symbol)+new BigDecimal(Double.parseDouble(current_price)).setScale(1,java.math.BigDecimal.ROUND_HALF_UP));
				}else{
					holder.saved_price.setText(getIdToString(R.string.save)+ f1);
				}
//				holder.old_price.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
			}else{
				holder.saved_price.setText(getIdToString(R.string.no_original_price));
			}
			convertView.invalidate();
			return convertView;
		}

	}
	/**
	 * 	  判断是否为 null
	 * @param str
	 * @return false 代表 null
	 */
	public Boolean isNull(String str){
		if(str!=null&&!str.equals("")&&str!=""&&!str.equals("null")){
			return true;
		}
		return false;
	}
	private OnItemClickListener clickListenerShop = new OnItemClickListener() {
		
		public void onItemClick(AdapterView<?> parent, View view, int position,long id) {
			MSystem.detail+=1;
			MSystem.pv+=1;
			if(HomeActivity.dataSource.get(HomeActivity.dataType).size()!=0&&position<HomeActivity.dataSource.get(HomeActivity.dataType).size()){
				Shop shop = HomeActivity.dataSource.get(HomeActivity.dataType).get(position);
				Intent intent_shop = new Intent(ShoppingsActivity.this, ShopDetailActivity.class);
				intent_shop.putExtra("position", position);
				ShoppingsActivity.this.startActivity(intent_shop);
			}
		}
	};
	private OnScrollListener listScrollListenerShop = new ListView.OnScrollListener(){
        public void onScroll(AbsListView arg0,
                        int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        	   if (totalItemCount <= 0){
                    return;
                }
                if (firstVisibleItem + visibleItemCount >= (totalItemCount)&&totalItemCount!=1){
                	getShops();
                }
        }
		
		public void onScrollStateChanged(AbsListView view, int scrollState) {
			
		}
	};
	
	/**
	 * 显示等待进度条(加载数据)
	 */
	public void showWait() {
		this.runOnUiThread(new Runnable() {
			public void run() {
//					wait_content.setText(getIdToString(R.string.loading));
//					bottom_linear.setVisibility(View.VISIBLE);
			}
		});
	}
	String getIdToString(int id){
		String string=this.getResources().getString(id);
		return string;
	}
	
 
	public boolean getNetConnectState(Context context) {
		boolean netConnect = false;
		ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo info = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
		NetworkInfo infoM = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
		if (info.isConnected() || infoM.isConnected()) {
			netConnect = true;
		}
		return netConnect;
	}
	
	public void select_distance(){
		Dialog dialog = null;
		Builder b2 = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.AlertDialogCustom));
		b2.setTitle("选择距离");
        b2.setItems(R.array.select_distance, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
            	
            	if(which==0){
            		distance = "300000000";
            		home_btn2.setText("距离");
            	}else if(which==1){
            		distance = "0.5";
            		home_btn2.setText(500+"米");
            	}else if(which==2){
            		distance = "1";
            		home_btn2.setText(1000+"米");
            	}else if(which==3){
            		distance = "2";
            		home_btn2.setText(2000+"米");
            	}else if(which==4){
            		distance = "3";
            		home_btn2.setText(3000+"米");
            	}else if(which==4){
            		distance = "5";
            		home_btn2.setText(5000+"米");
            	}
            	
            	
            	
            	
            	sort=0;
            	initDataSource();
				adapterShop.setDate(new ArrayList<Shop>());
				adapterShop.notifyDataSetChanged();
				getShops();
            	 
            }
        });
        dialog = b2.create();
        dialog.show();
	}
	
	
	
    
    public boolean onKeyDown(int keyCode, KeyEvent event) {
    	if (keyCode == KeyEvent.KEYCODE_BACK) {
    		if(ShopDetailActivity.mList.contains(this)){
    			ShopDetailActivity.mList.remove(this);
			}
//    		MSystem.exit(this);
    		if(parentTab!=null){
	    		 parentTab.mHost.setCurrentTabByTag("home_tab");
	    		 parentTab.main_tab_home.setChecked(true);
    		}else{
    			this.finish();
    		}
    		
    		return true;
	    }else{
	    	return super.onKeyDown(keyCode, event);
	    }
    }


	
	public boolean onTouch(View v, MotionEvent event) {
		// TODO Auto-generated method stub
		
		switch (event.getAction()) {
		case MotionEvent.ACTION_DOWN:
			
//				textMap.get(v.getId()).setTextColor(Color.WHITE);
//				iconMap.get(v.getId()).setBackgroundResource(R.drawable.bg_btn);
			
//				if(v.getId()==R.id.home_left){
//					home_btn1.setTextColor(color.white);
//					home_icon1.setBackgroundResource(R.drawable.bg_btn);
//				}else if(v.getId()==R.id.home_center){
//					home_btn2.setTextColor(color.white);
//					home_icon2.setBackgroundResource(R.drawable.bg_btn);
//					
//				}else if(v.getId()==R.id.home_right){
//					home_btn2.setTextColor(color.white);
//					home_icon2.setBackgroundResource(R.drawable.bg_btn);
//				}
			break;
		case MotionEvent.ACTION_CANCEL:
			
//			textMap.get(v.getId()).setTextColor(color.black);
//			iconMap.get(v.getId()).setBackgroundResource(R.drawable.icon);
			
//			if(v.getId()==R.id.home_left){
//				home_btn1.setTextColor(color.black);
//				home_icon1.setBackgroundResource(R.drawable.icon);
//			}else if(v.getId()==R.id.home_center){
//				home_btn2.setTextColor(color.black);
//				home_icon2.setBackgroundResource(R.drawable.icon);
//				
//			}else if(v.getId()==R.id.home_right){
//				home_btn2.setTextColor(color.black);
//				home_icon2.setBackgroundResource(R.drawable.icon);
//			}
			break;
		case MotionEvent.ACTION_UP:
//			textMap.get(v.getId()).setTextColor(color.black);
//			textMap.get(v.getId()).setVisibility(View.VISIBLE);
//			iconMap.get(v.getId()).setBackgroundResource(R.drawable.icon);
//			if(v.getId()==R.id.home_left){
//				home_btn3.setTextColor(color.black);
//				home_icon3.setBackgroundResource(R.drawable.icon);
//			}else if(v.getId()==R.id.home_center){
//				home_btn3.setTextColor(color.black);
//				home_icon3.setBackgroundResource(R.drawable.icon);
//				
//			}else if(v.getId()==R.id.home_right){
//				home_btn3.setTextColor(color.black);
//				home_icon3.setBackgroundResource(R.drawable.icon);
//			}
			break;

		default:
			break;
		}
		
		return false;
	}
    
}
